{% extends 'InfoCollect/base.html' %}
    {% block title %}
            <title>旁站探测</title>
    {% endblock %}
{% block body %}
      <div class="container">
  <div class="jumbotron">
    <h1>旁站探测</h1>
    <div style="padding: 50px 0;">
      <form class="bs-example bs-example-form" role="form">
        <div class="row">
          <div class="col-lg-10">
            <div class="input-group">
              <input id="inputField" type="text" class="form-control" placeholder="请输入域名获取旁站探测，example:baidu.com">
              <span class="input-group-btn">
                <button class="btn btn-primary" type="button" onclick="startScan()">Start Scanning</button>
              </span>
            </div>
          </div>
        </div>
      </form>
    </div>
    <p id="scanStatus"></p>
  </div>
</div>
<table class="table">
  <thead id="scanResultHead">
  </thead>
  <tbody id="scanResult">
    <!-- 这里的内容将由JavaScript动态生成 -->
  </tbody>
</table>
    <script>
function startScan() {
    // 清空表格内容
    $('#scanResultHead').empty();
    $('#scanResult').empty();
    $('#scanStatus').text('正在全力获取旁站信息中，请稍等...');
    var inputText = $('#inputField').val().trim();
    if(inputText !== '') {
        $.ajax({
            type: "POST",
            url: "{% url 'InfoCollect:getsideline' %}",
            data: {input: inputText},
            success: function(response) {
              if ('scan_result' in response) {
                  console.log(response)
                    $('#scanStatus').text('扫描完成');
                    $('#scanResultHead').html('<tr><th>序号</th><th>域名</th><th>标题</th></tr>');
                    var sidelineScanData = response['scan_result'];
                    sidelineScanData.forEach(function(entry,index) {
                    var domain = entry.domain;
                    var title = entry.title;
                    var row = '<tr><td>' + (index + 1) + '</td><td>' + domain + '</td><td>' + title + '</td></tr>';
                    $('#scanResult').append(row);
});
                }
            },
            error: function(xhr, status, error) {
                console.error('发生错误：', error);
                alert(error);
            }
        });
    } else {
        alert('请输入要扫描的内容');
    }
}
</script>
{% endblock body %}